﻿package action;
import dao.*;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport{
	private String username;
	private String password;
	private String tip;

	public void setUsername(String username) {
		this.username = username;
	}
	public String getUsername() {
		return username;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	public String getPassword() {
		return password;
	}

	public void setTip(String tip) {
		this.tip = tip;
	}
	public String getTip() {
		return tip;
	}
	
	@Override
	public String execute() throws Exception{
		ActionContext ac=ActionContext.getContext();
		Map session=ac.getSession();

		if(username==null||password==null)
			return INPUT;
		UsersDAO dao=new UsersDAO();
	    List users=dao.findUserByNameAndPassword(username, password);
        if(!users.isEmpty()){
		    ActionContext.getContext().getSession().put("User",username);
        	//tip="欢迎您，"+username;
		    return SUCCESS;
        }
		else{
			addActionError("用户名或密码输入有误");
			return INPUT;
		}	
	}	
}